package com.cs.code.model;

import com.cs.core.util.StringUtil;
import com.cs.core.util.ParamUtil;
import com.cs.code.enums.NameType;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @package com.cs.core.model
 * @class NameModel
 * @desc 文件命名模型
 * @author wind
 * @date    2023/9/19 14:54
 * @version v1.0
 */
public class CsName implements Serializable {
    /**
     * 模块名称
     */
    private String module;

    /**
     * 文件命名规范
     */
    private NameType nameType;

    /**
     * 指定文件名称
     */
    private String name;

    /**
     * 文件名前缀
     */
    private String prefix;

    /**
     * 文件名后缀
     */
    private String suffix;

    /**
     * 文件名
     */
    private String fileType;

    private Map<String, Object> map;

    private CsName() {
        this.nameType = NameType.DEFAULT;
        this.suffix = "";
        this.fileType = "java";
        this.module = "";
        this.prefix = "";
        this.map = new HashMap<>();
    }

    public NameType getNameType() {
        return nameType;
    }

    public void setNameType(NameType nameType) {
        this.nameType = nameType;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Builder newBuilder(){
        return new Builder();
    }

    public static class Builder {
        private final CsName nameModel;

        public Builder(){
            this.nameModel = new CsName();

        }

        public Builder module(String module){
            if(StringUtil.isNotBlank(module)){
                this.nameModel.module = module;
            }
            return this;
        }

        public Builder fileType(String fileType){
            if(StringUtil.isNotBlank(fileType)){
                this.nameModel.fileType = fileType;
            }
            return this;
        }

        public Builder nameType(NameType nameType){
            if(nameType != null){
                this.nameModel.nameType = nameType;
            }
            return this;
        }

        public Builder name(String name){
            if(StringUtil.isNotBlank(name)){
                this.nameModel.name = name;
            }
            return this;
        }
        public Builder suffix(String suffix){
            if(StringUtil.isNotBlank(suffix)){
                this.nameModel.suffix = suffix;
            }
            return this;
        }

        public Builder prefix(String prefix){
            if(StringUtil.isNotBlank(prefix)){
                this.nameModel.prefix = prefix;
            }
            return this;
        }

        public Builder put(String key, Object value){
            if(StringUtil.isNotBlank(key)){
                this.nameModel.map.put(key, value);
            }
            return this;
        }

        public Builder put(Map<String, Object> map){
            if(map != null){
                this.nameModel.map.putAll(map);
            }
            return this;
        }

        public CsName build(){
            ParamUtil.notEmpty(this.nameModel.module, "模板名称不能为空");
            return this.nameModel;
        }
    }
}
